<template>

会员等级<select v-model="LevelsId">
    <option :value="0">--请选择--</option>
    <option  v-for="item in MemberLevel" :value="item.LevelId">{{ item.LevelName }}</option>
</select>
姓名:<input type="text" v-model="MemberName">
手机号:<input type="text" v-model="MemberPhone">
会员卡号:<input type="text" v-model="MemberCode">
身份证号:<input type="text" v-model="MemberCardId">
<input type="button" value="查询" @click="LoadData">

<table border="1">
<tr>
    <td style="align-content:35px;">会员显示</td>
</tr>
<thead>
    <tr style="background-color: aqua;">
        <td>姓名</td>
        <td>手机号</td>
        <td>身份证号</td>
        <td>本店消费</td>
        <td>会员等级名称</td>
        <td>积分余额</td>
        <td>会员卡号</td>
        <td>生日</td>
        <td>操作</td>
        
    </tr>
</thead>
<tbody>
    <tr v-for="item in Members">
        <td>{{item.M_Name}}</td>
        <td>{{item.M_Phone}}</td>
        <td>{{item.M_CardId}}</td>
        <td>{{item.M_Money.toFixed(2)}}</td>
        <td>{{item.LevelName}}</td>
        <td>{{item.Imgart.toFixed(2)}}</td>
        <td>{{item.Code}}</td>
        <td>{{ item.Birthday.substring(0,10) }}</td>
        <td>操作
            <a href="#" @click="Delte(item.M_Id)">删除</a>
            <a href="#" @click="Jump(item.M_Id)">修改</a>
        </td>
        
    </tr>
</tbody>
</table>


</template>
<script setup lang="ts">

import axios from 'axios';
import { onMounted,ref } from 'vue';

const Jump=(M_Id:string)=>{
    localStorage["M_Id"]=M_Id;
    location.href='/Update';
}
const LevelsId=ref(0);
const MemberName=ref("");
const MemberPhone=ref("");
const MemberCode=ref("");
const MemberCardId=ref("");

const Members=ref([{

    LevelName:"",
    M_Id:"",
    M_Name:"",
    M_CardId:"",
    M_Phone:"",
    Birthday:"",
    Imgart:0,
    M_Money:0,
    IsDel:"",
    LevelId:1,
    Code:""



}])


const MemberLevel=ref([{
    LevelId:0,
    LevelName:"",

}])

onMounted(()=>{
    LoadLevel();
    LoadData();
   
})
//等级下拉
const LoadLevel=()=>{
axios.get('https://localhost:7177/api/Member/ShowLevel')
.then(res=>{
 MemberLevel.value=res.data;

})

}
//显示
const LoadData=()=>{
    axios.get('https://localhost:7177/api/Member/ShowMember')

    .then(res=>{
        console.log(res.data)
        Members.value=res.data;
    })


}
//逻辑删除
const Delte=(M_Id:string)=>{
if(confirm("你确定要删除吗?")){

    axios.get('https://localhost:7177/api/Member/DeleteMember',
    
    {
        params:{
            M_Id:M_Id
        }
    }
    
    )
    .then(res=>{
        if(res.data>0){
            alert("删除成功");
            LoadData();
        }
        else{
            alert("删除失败");
        }
    })

}

}

</script>